package com.kent.internet;

/**
 * Notice: 断点下载工具的main方法
 *
 * @author kent_sun
 * @version 1.0
 * @date 2021/4/29
 * @since 1.0
 */
public class MultiThreadDown {
    public static void main(String[] args) throws Exception {
        // 初始化DownUtil对象
        final var downUtil = new DownUtil("https://fkjava.org/2020/04/01/ssm/ssm_cover.png",
                "ios.png", 4);
        // 开始下载
        downUtil.download();
        new Thread(() -> {
            while (downUtil.getCompleteRate() < 1) {
                // 每隔0.1s查询一次任务的完成进度
                // GUI程序中可根据改进度来绘制进度条
                System.out.println("已完成：" + downUtil.getCompleteRate());
                try {
                    Thread.sleep(100);
                } catch (Exception ex) {
                }
            }
        }).start();
    }
}
